// lib/tooltip_widget.dart
// 气泡框组件

import 'package:flutter/material.dart';

class TooltipWidget extends StatelessWidget {
  final String content;
  final double left;
  final double top;

  TooltipWidget({required this.content, required this.left, required this.top});

  @override
  Widget build(BuildContext context) {
    return Positioned(
      left: left,
      top: top,
      child: Material(
        color: Colors.transparent,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 箭头部分
            Container(
              width: 0,
              height: 0,
              decoration: BoxDecoration(
                // 边框用于做箭头效果
                border: Border(
                  top: BorderSide(color: Colors.transparent, width: 6),
                  left: BorderSide(
                    // color: Colors.red.withOpacity(0.8),
                    color: Colors.red, // 背景颜色为红色
                    // width: 6,
                    width: 10,
                  ),
                  right: BorderSide(color: Colors.transparent, width: 6),
                  bottom: BorderSide(color: Colors.transparent, width: 6),
                ),
                boxShadow: [
                  BoxShadow(
                    color: Color(0xFF3d1c5c), // 阴影颜色
                    blurRadius: 1, // 模糊半径
                    spreadRadius: 0, // 扩散半径
                    offset: Offset(0, 0), // 阴影偏移
                  ),
                ],
              ),
              transform: Matrix4.translationValues(-6, -18, 0), // 向上移动箭头
            ),
            // 气泡框部分
            Container(
              padding: EdgeInsets.all(10),
              decoration: BoxDecoration(
                // color: Colors.red.withOpacity(0.8),
                color: Colors.red, // 背景颜色为红色
                borderRadius: BorderRadius.circular(8),
                boxShadow: [
                  BoxShadow(
                    color: Color(0xFF3d1c5c), // 阴影颜色
                    blurRadius: 1, // 模糊半径
                    spreadRadius: 0, // 扩散半径
                    offset: Offset(0, 0), // 阴影偏移
                  ),
                ],
                // 为气泡框加上统一的边框
                // border:
                //     Border.all(color: Colors.red.withOpacity(0.8), width: 1),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  // 内容
                  Text(
                    content,
                    style: TextStyle(color: Colors.white),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
